//package com.example.demo.cloud.customer.exception;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.TypeReference;
//import com.example.demo.common.exception.DemoException;
//import feign.Response;
//import feign.Util;
//import feign.codec.ErrorDecoder;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Configuration;
//
//import java.nio.charset.Charset;
//
//
///**
// * @Description
// * 解决Spring Cloud中feign异常无法传递的问题，跨链路调用client端异常无法正确捕获
// * 高版本的cloud 可能不存在此问题
// * @create 2019-04-24 13:37
// **/
//@Configuration
//public class ExceptionErrorDecoder implements ErrorDecoder {
//    Logger log = LoggerFactory.getLogger(
//        ExceptionErrorDecoder.class);
//    @Override
//    public Exception decode(String var1, Response response) {
//        try {
//            if (response.body() != null) {
//                Response.Body body1 = response.body();
//
//                String body = Util.toString(response.body().asReader(Charset.defaultCharset()));
//                log.error(body);
//                ExceptionInfo exceptionInfo = JSON.parseObject(body, new TypeReference<ExceptionInfo>() {
//                    });
//                Class clazz = Class.forName(exceptionInfo.getException());
//                return (Exception) clazz.getDeclaredConstructor(String.class)
//                    .newInstance(exceptionInfo.getMessage());
//            }
//        } catch (Exception var4) {
//            log.error(var4.getMessage());
//            return new DemoException(var4.getMessage());
//        }
//        return new DemoException("系统异常,请联系管理员");
//    }
//}
